package com.drug.web.controller.wms;

import com.drug.common.annotation.Log;
import com.drug.common.core.controller.BaseController;
import com.drug.common.core.domain.AjaxResult;
import com.drug.common.core.page.TableDataInfo;
import com.drug.common.enums.BusinessType;
import com.drug.common.utils.poi.ExcelUtil;
import com.drug.wms.domain.BusManufacturerInfo;
import com.drug.wms.service.IBusManufacturerInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 生产厂商Controller
 *
 * @author ruoyi
 * @date 2021-11-06
 */
@RestController
@RequestMapping("/manuf/info")
public class BusManufacturerInfoController extends BaseController {
    @Autowired
    private IBusManufacturerInfoService busManufacturerInfoService;

    /**
     * 查询生产厂商列表
     */
    @PreAuthorize("@ss.hasPermi('system:info:list')")
    @GetMapping("/list")
    public TableDataInfo list(BusManufacturerInfo busManufacturerInfo) {
        startPage();
        List<BusManufacturerInfo> list = busManufacturerInfoService.selectBusManufacturerInfoList(busManufacturerInfo);
        return getDataTable(list);
    }

    /**
     * 导出生产厂商列表
     */
    @PreAuthorize("@ss.hasPermi('system:info:export')")
    @Log(title = "生产厂商" , businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(BusManufacturerInfo busManufacturerInfo) {
        List<BusManufacturerInfo> list = busManufacturerInfoService.selectBusManufacturerInfoList(busManufacturerInfo);
        ExcelUtil<BusManufacturerInfo> util = new ExcelUtil<BusManufacturerInfo>(BusManufacturerInfo.class);
        return util.exportExcel(list, "生产厂商数据");
    }

    /**
     * 获取生产厂商详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:info:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id) {
        return AjaxResult.success(busManufacturerInfoService.selectBusManufacturerInfoById(id));
    }

    /**
     * 新增生产厂商
     */
    @PreAuthorize("@ss.hasPermi('system:info:add')")
    @Log(title = "生产厂商" , businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BusManufacturerInfo busManufacturerInfo) {
        return toAjax(busManufacturerInfoService.insertBusManufacturerInfo(busManufacturerInfo));
    }

    /**
     * 修改生产厂商
     */
    @PreAuthorize("@ss.hasPermi('system:info:edit')")
    @Log(title = "生产厂商" , businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BusManufacturerInfo busManufacturerInfo) {
        return toAjax(busManufacturerInfoService.updateBusManufacturerInfo(busManufacturerInfo));
    }

    /**
     * 删除生产厂商
     */
    @PreAuthorize("@ss.hasPermi('system:info:remove')")
    @Log(title = "生产厂商" , businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids) {
        return toAjax(busManufacturerInfoService.deleteBusManufacturerInfoByIds(ids));
    }
}
